/**
 * @author: Loy-winters1224@163.com
 * @date: 2014-8-21-下午4:28:58
 */
package net.loyintean.pearlshell.wechat.distribute.impl;

import net.loyintean.pearlshell.wechat.common.EventEnum;
import net.loyintean.pearlshell.wechat.common.MessageTypeEnum;
import net.loyintean.pearlshell.wechat.distribute.IMessageDistributor;
import net.loyintean.pearlshell.wechat.model.BaseMessageModel;
import net.loyintean.pearlshell.wechat.model.event.EventMessageModel;
import net.loyintean.pearlshell.wechat.service.IMessageProcesser;
import net.loyintean.pearlshell.wechat.service.subs.SubsEventProcessorImpl;

/**
 * distribute message for subscribe message.
 * 
 * @author Loy-winters1224@163.com
 * @version 2014-8-21.1.0.0
 */
public class SubsDistributorImpl implements IMessageDistributor {

	private IMessageProcesser processer = new SubsEventProcessorImpl();

	/**
	 * 
	 * @author Loy-winters1224@163.com
	 * @see net.loyintean.pearlshell.wechat.distribute.IMessageDistributor
	 *      #distribute(net.loyintean.pearlshell.wechat.model.BaseMessageModel)
	 * 
	 */
	@Override
	public IMessageProcesser distribute(BaseMessageModel message) {
		assert message != null;

		EventMessageModel event;

		if (MessageTypeEnum.event.equals(message.getMsgType())) {
			event = (EventMessageModel) message;
		} else {
			event = null;
		}

		if (event != null && EventEnum.subscribe.equals(event.getEvent())) {
			return processer;
		}

		return null;
	}
}
